var Item = {
    //打开新窗口
    openNewWind :function (url) {
        //window.wakeup && window.wakeup( url );
        if(url.indexOf("http") != 0){
            url = JumpUrl+url;
        }
        if(isWx === '1'){

            layer.confirm('当前浏览器阻止浏览淘宝链接，请复制链接，使用其他浏览器打开！', {
                btn: ['复制链接','拒绝复制'] //按钮
            }, function(){
                var btn = $("#js_copy_do");
                btn.attr("data-copy",url);
                btn.click();
            }, function(){

            });
        }else {
            window.location.href = url;
        }

    },
    detail:function (obj) {
        var ths = $(obj);
        var url = ths.attr("href");
        var $btn = ths.button('loading');
        layer.load(2);
        $.ajax({
            url: url,
            type: 'get',
            dataType: 'json',
            success: function (res) {
                layer.closeAll('loading');
                if(res.status == 200 && res.is_wx == 1){
                    $btn.button('reset');
                    var str = "复制这条信息，"+res.data.code+"，打开【手机淘宝】即可领券下单购买";
                    layer.confirm(str, {
                        btn: ['复制链接','拒绝复制'] //按钮
                    }, function(){
                        var btn = $("#js_copy_do");
                        btn.attr("data-copy",str);
                        btn.click();
                    }, function(){

                    });
                }else if(res.status == 200){
                    window.location.href = res.data.url;
                }
                if(res.status == 300){
                    layer.msg("优惠券过期了，请换其他商品。");
                }
            },
            error:function(){
                $btn.button('reset');
                layer.closeAll('loading');
            }
        });
        return false;
    }
};

//图片懒加载
var imgLoad = lazyload.init({selectorName:".lazy"});

jQuery(document).ready(function($){
    $(".js_detail").on("click",function(){
        layer.load(2);
        var ths = $(this);
        $.ajax({
            url: DetailUrl,
            type: 'get',
            data:{
                activityId:ths.data("quan"),
                itemId:ths.data("gid")
            },
            dataType: 'json',
            success: function (res) {
                layer.closeAll('loading');
                if(res.status == 0){
                    Item.openNewWind(res.data.url);
                }
                if(res.status == 1){
                    layer.msg("链接打开失败，请稍后重试");
                }
            },
            error:function(){
                layer.closeAll('loading');
            }
        });
    });


    $("#js_copy_do").on("click",function(){
        var clipboard = new Clipboard('#js_copy_do', {
            //动态设置复制内容
            text:function(trigger) {
                return trigger.getAttribute('data-copy');
            }
        });
        clipboard.on('success', function(e){
            layer.msg("复制成功");
        });
        clipboard.on('error', function(e) {
            layer.msg("链接复制失败，当前浏览器不支持");
        });
    });
});